﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Catering_Model;
using Catering_Operation;
using System.Data;

namespace Catering_Rules
{
    public class SMS_MsgBLL
    {

        public DataTable GetOutBox(string senderID, string isDel)
        {
            SMS_MsgDAL dal = new SMS_MsgDAL();
            return dal.GetOutBox(senderID, isDel);
        }

        public bool addsms(SMS_MsgInfo smsInfo, string[] receiverIDs)
        {
            SMS_MsgDAL dal = new SMS_MsgDAL();
            bool flag = false;
            int num = dal.addsms(smsInfo, receiverIDs);
            if (num > 0)
            {
                flag = true;
            }
            return flag;
        }

        public DataRow GetOutBox(string id)
        {
            SMS_MsgDAL dal = new SMS_MsgDAL();
            return dal.GetOutBox(id);
        }

        /// <summary>
        /// 收件箱
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="isDel">是否删除</param>
        /// <returns></returns>
        public DataTable GetInBoxByUserID(string userID, string isDel)
        {
            SMS_MsgDAL dal = new SMS_MsgDAL();
            return dal.GetInBoxByUserID(userID, isDel);
        }

        /// <summary>
        /// 查询单条信息
        /// </summary>
        /// <param name="id">信息id</param>
        /// <param name="table">选择收件箱或发件箱</param>
        /// <returns></returns>
        public DataRow GetSingleMes(string id)
        {
            SMS_MsgDAL dal = new SMS_MsgDAL();
            dal.updateRead(id);
            return dal.GetInBox(id);
        }

        /// <summary>
        /// 查询单条信息
        /// </summary>
        /// <param name="id">信息id</param>
        /// <param name="table">选择收件箱或发件箱</param>
        /// <returns></returns>
        public DataTable GetSingleMes(string id, string table)
        {
            SMS_MsgDAL dal = new SMS_MsgDAL();
            if (table.Equals("View_Of_InBox"))
            {
                dal.updateRead(id);
            }
            return dal.GetSingleMes(id, table);
        }

        /// <summary>
        /// 删除已发送信息
        /// </summary>
        /// <param name="id">信息ID</param>
        /// <returns></returns>
        public bool doDelInBox(string id)
        {
            bool flag = false;
            SMS_MsgDAL dal = new SMS_MsgDAL();
            int num = dal.doDelInBox(id);
            if (num > 0)
            {
                flag = true;
            }
            return flag;
        }

        /// <summary>
        /// 删除收件箱信息
        /// </summary>
        /// <param name="id">信息ID</param>
        /// <returns></returns>
        public bool doDelOutBox(string id)
        {
            bool flag = false;
            SMS_MsgDAL dal = new SMS_MsgDAL();
            int num = dal.doDelOutBox(id);
            if (num > 0)
            {
                flag = true;
            }
            return flag;
        }

        /// <summary>
        /// 查询未读短信
        /// </summary>
        /// <param name="rid">接受人ID</param>
        /// <returns></returns>
        public int GetUNReadCount(string rid)
        {
            SMS_MsgDAL dal = new SMS_MsgDAL();
            return dal.GetUNReadCount(rid);
        }
    }
}
